import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue({
      template: {
        // 禁用模板中的一些严格规则以兼容DataV
        compilerOptions: {
          whitespace: 'preserve'
        }
      }
    }),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    hmr: {
      // 禁用HMR错误覆盖
      proxy: {
        '/api': {
          target: 'http://localhost:8080', // 后端地址
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      },
      overlay: false
    }
  }
})
